package com.example.tutorials;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.example.hibernate.core.HibernateCommunicator;
import com.example.login.ILoginService;
import com.example.service.IService;
import com.example.service.IServiceManager;
import com.example.service.ServiceManager;

public class MyServerStartUp implements ServletContextListener {
	
	private static Logger logger = Logger.getLogger("com.example.tutorials.MyServerStartUp");
	private static FileHandler fh = null;
	static{
	
		try{
			fh = new FileHandler("myLog.txt");
			logger.addHandler(fh);
			logger.setLevel(Level.ALL);
		}catch(Exception e){
			
		}
	}
	
	
	public void contextDestroyed(ServletContextEvent arg0) {
		((ILoginService)ServiceManager.getInstance().getService(IService.LOGINSERVICE)).logoutAllUsers();
		HibernateCommunicator.getInstance().closeDown();

	}

	public void contextInitialized(ServletContextEvent arg0) {
//		logger.info("Starting the Vaadin FunFusion Content Management Application");
		IServiceManager sm = ServiceManager.getInstance();
		sm.init();
		HibernateCommunicator.getInstance();
	}

}
